<?php
/**
 * Created by PhpStorm.
 * User: Shinelon
 * Date: 2021/1/16
 * Time: 10:41
 */

namespace app\admin\model;


use app\BaseModel;

class WxappModel extends BaseModel
{
    protected  $name='account_wxapp';

    /**
     * 创建
     */
    public function createWxapp($data)
    {
        $data['create_time'] = time();
        $result = $this->save($data);
        return !empty($result);
    }

    //修改
    public function updateWxapp($filter ,$data)
    {
        $data['update_time'] = time();
        $result = $this->where($filter)->update($data);
        return !empty($result);
    }

    //获取分页
    public function listWxapp($filter ,$page_config)
    {
        $start_row = ($page_config['page'] - 1) * $page_config['page_count'];
        $end_row   = $page_config['page_count'];
        $result    = $this->where($filter)
            ->order('create_time' ,'desc')
            ->limit($start_row ,$end_row)
            ->select();
        if(!empty($result)) $result = $result->toArray();
        return $result;
    }

    //获取分页
    public function allWxapp($filter)
    {
        $result    = $this->where($filter)
            ->order('create_time' ,'desc')
            ->select();
        if(!empty($result)) $result = $result->toArray();
        return $result;
    }

    //获取数据总数
    public function listWxappCount($filter)
    {
        $result = $this->where($filter)
            ->count();
        return $result;
    }

    /**
     * 获取
     */
    public function getWxapp($filter)
    {
        $filter['deleted'] = 0;
        $result = $this->where($filter)->find();
        if(!empty($result)) $result = $result->toArray();
        return $result;
    }

    //删除
    public function delWxapp($filter)
    {
        $data['delete_time'] = time();
        $data['deleted'] = 1;
        $result = $this->where($filter)->update($data);
        return !empty($result);
    }

}